/*
 * @Author: xiawei 1243162387@qq.com
 * @Date: 2023-12-06 16:32:19
 * @LastEditors: xiawei 1243162387@qq.com
 * @LastEditTime: 2024-04-26 20:15:48
 */
export const getFields = () => {
    const JNOptions = [
        { label: 'react', value: 1 },
        { label: 'vue2', value: 0 },
        { label: 'vue3', value: 3 },
        { label: 'java', value: 2 },
        { label: 'SQL', value: 4 },
        { label: 'PHP', value: 5 },
        { label: 'node', value: 6 },
        { label: 'GO', value: 7 },
    ]
    return [
        {
            type: 'input', prop: 'username', label: '姓名', col: 12, showWordLimit: true, maxLength: 20, rules: [
                {
                    required: true,
                    message: '姓名必填',
                    trigger: 'blur',
                }
            ]
        },
        {
            type: 'input', prop: 'age', label: '年龄', col: 12, rules: [
                {
                    required: true,
                    message: '年龄必填',
                    trigger: 'blur',
                },
                {
                    validator(_rule: any, _value: any, _callback: any, _source: any, _options: any) {
                        const errors: Array<string> = [];
                        if(!/^\d+(\.{1}\d+)?$/.test(_value)){
                            errors.push('请输入数字字符')
                        }
                        return errors;
                      }
                }
            ],
            // 自动填充
            linkageFillOrClear: (fromData: any) => {
                if (fromData) {
                    if(fromData.age>= 18){
                        fromData['jh'] = { label: '是', value: 1 }
                    }else{
                        fromData['jh'] = null
                    }
                }
            }
        },
        {
            type: 'select', prop: 'jh', col: 12, label: '是否已婚', options: [{ label: '是', value: 1 }, { label: '否', value: 0 }], rules: [
                {
                    required: true,
                    message: '必填',
                    trigger: 'change',
                }
            ],
            // 联动disabled
            linkageDisabled: (fromData: any) => {
                const age = fromData?.['age']
                return age ? age < 18 : false
            },
            linkageRequired: (fromData: any) => {
                const age = fromData?.['age']
                return age ? !(+age < 18) : false
            }
        },
        // stateTime<-->endTime 日期联动限制选项
        {
            type: 'date', prop: 'stateTime', col: 12, label: '开始时间', dateMaxLimit: 'endTime', rules: [
                {
                    required: true,
                    message: '开始日期必填',
                    trigger: 'blur',
                }]
        },
        {
            type: 'date', prop: 'endTime', col: 12, label: '结束时间', dateMinLimit: 'stateTime', rules: [
                {
                    required: true,
                    message: '结束日期必填',
                    trigger: 'blur',
                }]
        },
        {
            type: 'select', prop: 'zy', col: 12, label: '职业', options: [{ label: 'web前端工程师', value: 1 }, { label: 'java后端工程师', value: 0 }], rules: [
                {
                    required: true,
                    message: '必填',
                    trigger: 'change',
                }
            ],
            linkageFillOrClear: (fromData: any) => {
                if (fromData) {
                    fromData['jn'] = []
                }
            }
        },
        {
            type: 'checkbox', prop: 'jn', col: 12, label: '必备技能',
            options: JNOptions,
             rules: [
                {
                    required: true,
                    message: '技能必填',
                    trigger: 'blur',
                }],
            linkageOptions: (fromData: any) => {
                if(fromData && fromData['zy']){
                    if(fromData['zy'].value ===1){
                        return JNOptions.filter(item => [1,0,3,6].includes(item.value))
                    }
                    if(fromData['zy'].value ===0){
                        return JNOptions.filter(item => ![1,0,3,6].includes(item.value))
                    }
                    return JNOptions
                }
                return JNOptions
            }

        }
    ]
}